import 'dart:convert';

import 'package:spring_fairy/api/api.dart';
import 'package:spring_fairy/model/mood_point_image.dart';

class PointImageAPI extends API {
  Future<MoodPointImage?> addMoodPintImage(MoodPointImage data) async {
    var response = await sendJSONPostRequest("/images/create?pointId=${data.pointId}&url=${data.imageUrl}",{});

    if(response == null) {
      return null;
    }
    return MoodPointImage.fromJson(json.decode(response));
  }

  Future<List<MoodPointImage>?> getAllPointImage(int pointId) async {
    var response = await sendJSONPostRequest("/images/list?pointId=${pointId}",{});

    if(response == null) {
      return null;
    }
    var list = json.decode(response);
    var result = <MoodPointImage>[];
    for(int i = 0 ; i < list.length ; i++) {
      result.add(MoodPointImage.fromJson(list[i]));
    }
    return result;
  }
}